<?php

namespace catchAdmin\registration\controller;

use catcher\CatchResponse;
use catcher\base\CatchRequest;
use catcher\base\CatchController;
use app\common\model\FollowMessageTemplate as TemplateModel;
use app\common\model\FollowDeptMessageBd as BdModel;
use catchAdmin\registration\request\MessageRequest;

class FollowMessage extends CatchController
{
    protected $temp;

    public function __construct(TemplateModel $temp)
    {
        $this->temp = $temp;
    }

    /**
     * 列表
     * @time 2023年08月16日
     * @return \think\response\Json
     */
    public function index(): \think\response\Json
    {
        return CatchResponse::paginate($this->temp->getList());
    }

    /**
     * 添加
     * @param MessageRequest $request
     * @return \think\response\Json
     */
    public function save(MessageRequest $request): \think\response\Json
    {
        $req = $request->post();
        return CatchResponse::success($this->temp->addData($req));
    }

    /**
     * 更新
     * @param string $id 主键
     * @param CatchRequest $request
     * @return \think\response\Json
     */
    public function update(string $id, CatchRequest $request): \think\response\Json
    {
        return CatchResponse::success($this->temp->saveData($id, $request->post()));
    }

    /**
     * 删除
     * @param string $id
     * @return \think\response\Json
     */
    public function delete(string $id): \think\response\Json
    {
        return CatchResponse::success($this->temp->destroy($id));
    }

    /**
     * 随访消息字典
     * @time 2023年08月16日
     * @return \think\response\Json
     */
    public function follow_message_dic(): \think\response\Json
    {
        $data = $this->temp->field('id,title')->select();
        return CatchResponse::success($data);
    }

    /**
     * 绑定列表
     * @time 2023年08月16日
     * @return \think\response\Json
     */
    public function bd_index(): \think\response\Json
    {
        return CatchResponse::paginate((new BdModel())->getList());
    }

    /**
     * 绑定添加
     * @param CatchRequest $request
     * @return \think\response\Json
     */
    public function bd_save(CatchRequest $request): \think\response\Json
    {
        $req = $request->post();
        return CatchResponse::success((new BdModel())->addData($req));
    }

    /**
     * 绑定更新
     * @param string $id 主键
     * @param CatchRequest $request
     * @return \think\response\Json
     */
    public function bd_update(string $id, CatchRequest $request): \think\response\Json
    {
        return CatchResponse::success((new BdModel())->saveData($id, $request->post()));
    }

    /**
     * 绑定删除
     * @param string $id
     * @return \think\response\Json
     */
    public function bd_delete(string $id): \think\response\Json
    {
        return CatchResponse::success((new BdModel())->destroy($id));
    }
}